package com.nutiteq.location;

import java.util.Random;

import com.nutiteq.components.WgsPoint;

public class TestGPSSource extends Thread implements LocationSource {
  private WgsPoint locationPoint;
  private final double lonChange;
  private final double latChange;
  private static final Random R = new Random();
  private LocationMarker marker;
  private boolean running;

  public TestGPSSource(final WgsPoint startPoint, final double lonChange, final double latChange) {
    locationPoint = startPoint;
    this.lonChange = lonChange;
    this.latChange = latChange;
  }

  public void run() {
    running = true;
    while (running) {
      System.out.println("runme");
      marker.setLocation(getLocation());
      synchronized (this) {
        try {
          wait(1000);
        } catch (final InterruptedException ignore) {
        }
      }
    }
  }

  public WgsPoint getLocation() {
    locationPoint = new WgsPoint(locationPoint.getLon() + lonChange, locationPoint.getLat()
        + latChange);
    return locationPoint;
  }

  public int getStatus() {
    return R.nextInt() + 1;
  }

  public LocationMarker getLocationMarker() {
    return marker;
  }

  public void quit() {
    running = false;
    marker.quit();
  }

  public void setLocationMarker(final LocationMarker marker) {
    this.marker = marker;
    this.marker.setLocationSource(this);
  }

  public void addLocationListener(final LocationListener listener) {
    //TODO jaanus : !!!
  }
}
